/*
*       A simple 2D game map editor
*
*       This library is free software; you can redistribute it and/or
*       modify it under the terms of the GNU Lesser General Public
*       License as published by the Free Software Foundation; either
*       version 2.1 of the License, or (at your option) any later version.
*/
// Name        : com_process.cpp
// File        : com_process.cpp
// Description :
// Author      : hoha
// Date        : 26/09/2009
// Evolutions  : 26/09/2009, Version V0, Creation
//HEADER
#include "com_process.h"
//CONTENT

//get tile size
u32 com_get_file_size(FILE*fp)
{
  if(NULL!=fp)
  {
   fseek(fp, 0L, SEEK_SET);  //from begin
   u32 PosBegin = ftell(fp);     //get current pos
   fseek(fp, 0L, SEEK_END);  //to end
   u32 PosEnd = ftell(fp);       //get current pos
   u32 len= PosEnd - PosBegin;   //cac file size
   fseek(fp, 0L, SEEK_SET);  //set file pointer back
   return len;
  }
  else
  {
   printf("com_get_file_size: file pointer is NULL\n");
   return 0;
  }
}

bool com_check_file_exist(QString filename)
{
  QFile testfile;
  return testfile.exists(filename);
}

//get the tile name from the path&name
bool com_get_tile_name(const char* src, char *des)
{
   const char *p=src;
   char *d=des;
   u8 len=0;
   if(NULL==p)return false;
   while('\0'!=*p)p++;
   while('/'!=*p)
   {
       p--;
       len++;
   }
   if(len>20)
   {
       printf("tile name is too long, out of range.\n");
       return false;
   }
   p++;
   while('\0'!=*p)(*(d++)=*(p++));
   return true;
}

